[//
    async function( kuo,Context,context){
        Context.headers["content-type"] = 'application/json;charset=UTF-8';
        let $DATA = Object.assign({},this.$DATA);
        let $features = await Kuoplus(kuo.class);
        let $THIS =  this;
        let $_GET = kuo.get;
        let $LANG = this.LANG();
        let $appid  = $features['configure']['qq'] && $features['configure']['qq']['0']?$features['configure']['qq']['0']:"";
        let $secret  = $features['configure']['qq'] && $features['configure']['qq']['1']?$features['configure']['qq']['1']:"";
        let UID = 0;
        let $state  = $_GET['state']?$_GET['state']:"";
        let $CODE   = $_GET['code']?$_GET['code']:"";
        let $Security = await Mem.Get('opentoken/'+$state);
        let $redirect_uri = KuoLink( ['login','alipay_back']);
        if($Security){
            kuo.sessionid = $Security.sessionid;
            Mem.Del('opentoken/'+$state)
            let $CAN = {
                'grant_type':"authorization_code",
                "client_id":$appid,
                'client_secret':$secret,
                'code':$CODE,
                'redirect_uri':$redirect_uri,
                'fmt':'json'
            
            };
            
            let $fan = await GET("https://graph.qq.com/oauth2.0/token?"+ getarray($CAN));
           
            $fan = json_decode($fan);

            if(!$fan['access_token'] || !isset($fan['access_token'])){
                $DATA.code = -1;$DATA.data =$fan['error']; $DATA.msg = $fan['error_description'];Context.body = JSON.stringify($DATA);
                return ;
            }
            let $access_token = $fan['access_token']?$fan['access_token']:"";
            $fan  = await GET("https://graph.qq.com/oauth2.0/me?access_token="+$access_token +"&fmt=json&unionid=1");
            $fan = json_decode($fan);
            let $openid = $fan['openid']?$fan['openid']:"";
            let $unionid = $fan['unionid']?$fan['unionid']:"";
            if($unionid == ""){
                $DATA.code = -1;$DATA.data =$fan['error']; $DATA.msg = $LANG.unionid;Context.body = JSON.stringify($DATA);
                return ;
                
            }
            let $db =  await db('login_qq');
            let $user = await $db.Where( {'unionid': $unionid } ).Find();

            if( $user ){
                if($user['openid'] == ""){
                    await $db.Where( {'unionid': $unionid } ).Update( {'openid':$openid});
                }
                let $USER =  await Uid($user['uid']);
                if($USER['accountoff'] != 1){
                    $DATA.code = -1;  $DATA.msg = $LANG.accountoff;Context.body = JSON.stringify($DATA);
                    return ;
                   
                }
                $Security['uid'] = $user['uid'];
                await Mem.Put("session/"+kuo.sessionid,$Security,Expiredseconds);
                await  Kuolog('userlog',$user['uid'],0, [] ,kuo.func_,kuo.class,kuo.ip);
                if($Security.platform == "ISAPP"){
                    $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
                    $DATA.code = 1;
                    $DATA.msg = $LANG.login_true;
                    $DATA.data = $USER;
                    $DATA.apptoken = kuo.sessionid;
                    Context.body = JSON.stringify($DATA);
                }else{
                    let url = $Security.tiaozhuan?$Security.tiaozhuan:WZHOST;
                    Context.statusCode = 302;
                    Context.headers["Location"] = url ;
                    Context.body = "";
                }
                return ;
            }

            if($Security.uid && $Security.uid  > 0){
                //绑定用户
                UID = $Security.uid;
                let $chaxun = await $db.Where( {'uid': UID} ).Find();
                if($chaxun){
                    $DATA.code = -1;  $DATA.msg = $LANG.account_false;Context.body = JSON.stringify($DATA);
                    return ;
                }

            }else{

                let $getdata = {
                    "oauth_consumer_key":$appid,
                    'access_token' :$access_token,
                    'openid':$openid
                };
                $fan = GET("https://graph.qq.com/user/get_user_info?"+getarray($getdata ));
                $fan = json_decode($fan);

                $user = {
                    'nickname':$fan['nickname']?$fan['nickname']:$openid,
                    'sex':$fan['gender_type']?$fan['gender_type']:-1,
                    'headimgurl':$fan['figureurl_qq']?$fan['figureurl_qq']:""
                };
            
                let $SEX = { "-1":"1", "1":"1","2":"0"};
             
                UID = await $THIS.REG({
                    "name":$user.nickname,
                    "sex":   $SEX [$user['sex']]?$SEX [$user['sex']]:-1,
                    "tou": $user.headimgurl,
                    "ip":kuo.ip,
                    'tuid':$Security.tuid?$Security.tuid:0
                });
            }

            if(!UID || UID < 1){
                $DATA.code = -1; $DATA.msg = $LANG.uuid_error;Context.body = JSON.stringify($DATA);
                return ;
            }
            $user = {
    
                'openid':$openid,
                'unionid':$unionid,
                'uid': UID
            };
            $fan = $db.Insert($user);
            if($fan){
                
                $Security['uid'] = $user['uid'];
                await Mem.Put("session/"+kuo.sessionid,$Security,Expiredseconds);
                await  Kuolog('userlog',$user['uid'],0, [],kuo.func_,kuo.class,kuo.ip);
                
                if($Security.platform == "ISAPP"){
                    $USER = await Uid( $user['uid'] );
                    $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
                    $DATA.code = 1;
                    $DATA.msg = $LANG.reg_true;
                    $DATA.data = $USER;
                    $DATA.apptoken = kuo.sessionid;
                    Context.body = JSON.stringify($DATA);

                }else{
                    let url = $Security.tiaozhuan?$Security.tiaozhuan:WZHOST;
                    Context.statusCode = 302;
                    Context.headers["Location"] = url ;
                    Context.body = "";
                }

            }else{

                $DATA.code = -1;
                $DATA.msg = $LANG.reg_false;
                if($Security.platform == "ISAPP"){
                    Context.body = JSON.stringify($DATA);
                }else{
                    let url = $Security.tiaozhuan?$Security.tiaozhuan:WZHOST;
                    Context.statusCode = 302;
                    Context.headers["Location"] = url ;
                    Context.body = "";
                }
            }
                
            

        }else{
            $DATA.code = -1;
            $DATA.msg = $LANG.login_false;
            Context.body = JSON.stringify($DATA);
        }
    } 
]